package com.usian.login.lister;

import cn.hutool.core.util.RandomUtil;
import com.usian.third.code.AliCodeUtils;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.amqp.core.Message;

import java.util.concurrent.TimeUnit;

@Service
public class RabbitLister {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RabbitListener(queues="java-queue")
    public void sendLoginCode(Message message,String phone) throws Exception {
        System.out.println("监听到有消息产生");
        AliCodeUtils aliCodeUtils= new AliCodeUtils();
        String code= RandomUtil.randomNumbers(6);
        aliCodeUtils.sendLoginCode(phone, code);
        stringRedisTemplate.opsForValue().set(phone,code);
        stringRedisTemplate.expire(phone,5, TimeUnit.MINUTES );
    }

}
